﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;
using AppEntity;

namespace AppEntity
{
    public partial class App
    {

        public enum ColumnType
        {
            String,
            Date,
            /// <summary>
            /// HH:mm
            /// </summary>
            Time,
            /// <summary>
            /// HH:mm:ss
            /// </summary>
            Time2,
            /// <summary>
            /// yyyy-MM-ddTHH:mm:ss.fffk
            /// </summary>
            DateTime,
            Double,
            Integer,
            Bool
        }

        public class Column
        {
            public string Name;
            public ColumnType Type;
            public string DefaultValue;
            public string Title;
            public bool IsCore = false;
            public string Control;
            public Entity Entity;
            public App App;
            public string GetLangTitle(string Lang)
            {
                XmlNode Col = this.Entity.EntityDom.SelectSingleNode("/root/app/entity/columns/column[@name='{0}']/@{1}", this.Name, Lang);
                if (Col == null) return null;
                return Col.Value;
            }

            public static ColumnType ParseColumnType(string TypeName)
            {
                string Type = TypeName.ToLower();
                switch (Type)
                {
                    case "string":
                        {
                            return ColumnType.String;
                        }
                        break;
                    case "date":
                        {
                            return ColumnType.Date;
                        }
                        break;
                    case "time":
                        {
                            return ColumnType.Time;
                        }
                        break;
                    case "time2":
                        {
                            return ColumnType.Time2;
                        }
                        break;
                    case "datetime":
                        {
                            return ColumnType.DateTime;
                        }
                        break;
                    case "double":
                        {
                            return ColumnType.Double;
                        }
                        break;
                    case "integer":
                        {
                            return ColumnType.Integer;
                        }
                        break;
                    case "bool":
                        {
                            return ColumnType.Bool;
                        }
                        break;
                }
                return ColumnType.String;
            }
        }



    }
}